package net.wwang.demo.service;

import net.wwang.demo.dao.UserDao;
import net.wwang.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @BelongsProject: demo
 * @BelongsPackage: net.wwang.demo.config.security
 * @Author: WangWei
 * @CreateTime: 2020-06-02 10:55
 * @Description:
 */
@Service
public class UserService implements UserDetailsService {

    @Autowired
    private UserDao userDao;
    @Override
    public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
        User user = userDao.findUserByUsername(name);
        if(user==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        return  user;
    }

}
